/**
 * Created by hjqi on 2016/4/19.
 */

angular.module('NatureCloud').directive('hcChart', ['$window', function($window) {
    return {
        restrict: 'E',
        template: '<div></div>',
        scope: {
            title: '@',
            ytitle:'@',
            data: '=',
            loadfunc: '=',
            series:'='
        },
        link: function postLink(scope, element) {
            Highcharts.setOptions({
                global: {
                    useUTC: false
                }
            });

            Highcharts.chart(element[0], {
                chart: {
                    type: 'spline',
                    animation: Highcharts.svg, // don't animate in old IE
                    //marginRight: 10,
                    events: {
                        load: scope.loadfunc
                    }
                },
                title: {
                    text: scope.title
                },
                credits: {
                    enabled: false
                },
                xAxis: {
                    startOnTick: false,
                    type: 'datetime'
                },
                yAxis: {
                    title: {
                        text: scope.ytitle
                    },
                    plotLines: [{
                        value: 0,
                        width: 2,
                        color: '#808080',
                        spline: {
                            marker: {
                                enabled: false
                            }
                        }
                    }],
                    labels:{

                    }
                },
                tooltip: {
                    formatter: function () {
                        return '<b>' + this.series.name + '</b><br/>' +
                            Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                            Highcharts.numberFormat(this.y, 10);
                    }
                },
                legend: {
                    enabled: true
                },
                exporting: {
                    enabled: false
                },
                series:scope.series
            });
        }
    };
}]);